package com.example.dormitorysystem.controller;


import com.example.dormitorysystem.common.aop.OperationLogAnnotation;
import com.example.dormitorysystem.service.GroupsService;
import com.example.dormitorysystem.utils.Response;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 吉吉王国组
 * @since 2022-11-26
 */
@RestController
@RequestMapping("")
public class GroupsController {

    @Resource
    private GroupsService groupsService;

    @PostMapping("/team/create")
    @OperationLogAnnotation(operModul = "组队模块", operType = "setGroup", operDesc = "用户创建队伍")
    public Response setGroup(@RequestBody Map<String, Object> input, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> res = groupsService.setGroup(input, request, response);
        return Response.success().data(res);
    }

    @PostMapping("/team/del")
    @OperationLogAnnotation(operModul = "组队模块", operType = "deleteGroup", operDesc = "删除队伍")
    public Response delGroup(HttpServletRequest request, HttpServletResponse response) {
        groupsService.delGroup(request, response);
        return Response.success();
    }

    @PostMapping("/team/join")
    @OperationLogAnnotation(operModul = "组队模块", operType = "joinGroup", operDesc = "用户加入队伍")
    public Response joinGroup(@RequestBody Map<String, Object> input, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> res = groupsService.joinGroup(input, request, response);
        return Response.success().data(res);
    }

    @PostMapping("/team/quit")
    @OperationLogAnnotation(operModul = "组队模块", operType = "quitGroup", operDesc = "用户退出队伍")
    public Response quitGroup(HttpServletRequest request, HttpServletResponse response) {
        groupsService.quitGroup(request, response);
        return Response.success();
    }

    @GetMapping("/team/my")
    @OperationLogAnnotation(operModul = "组队模块", operType = "getMyGroupInfo", operDesc = "用户查询自己队伍信息")
    public Response myGroup(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> res = groupsService.myGroup(request, response);
        return Response.success().data(res);
    }

    @PostMapping("/team/transfer")
    @OperationLogAnnotation(operModul = "组队模块", operType = "transGroupLeader", operDesc = "用户转让队长")
    public Response transGroup(@RequestBody Map<String, Object> input, HttpServletRequest request, HttpServletResponse response) {
        groupsService.transGroup(input, request, response);
        return Response.success();
    }
}

